package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.EcosystemImage;
import com.fsnbigdata.domain.Ecosystem;
import com.fsnbigdata.domain.QEcosystemImage;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = EcosystemImageRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = EcosystemImageRepositoryCustom.class)
@Transactional(readOnly = true)
public class EcosystemImageRepositoryImpl extends QueryDslRepositorySupportExt<EcosystemImage> implements EcosystemImageRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    EcosystemImageRepositoryImpl() {
        super(EcosystemImage.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LOCATION = "location";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CODE = "code";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CREATE_DATE = "createDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DESCRIPTION = "description";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String AUTHOR = "author";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ECOSYSTEM = "ecosystem";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String URL = "url";

    /**
     * TODO Auto-generated method documentation
     *
     * @param ecosystem
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<EcosystemImage> findByEcosystem(Ecosystem ecosystem, GlobalSearch globalSearch, Pageable pageable) {
        QEcosystemImage ecosystemImage = QEcosystemImage.ecosystemImage;
        JPQLQuery<EcosystemImage> query = from(ecosystemImage);
        Assert.notNull(ecosystem, "ecosystem is required");
        query.where(ecosystemImage.ecosystem.eq(ecosystem));
        Path<?>[] paths = new Path<?>[] { ecosystemImage.ecosystem, ecosystemImage.code, ecosystemImage.description, ecosystemImage.location, ecosystemImage.author, ecosystemImage.url, ecosystemImage.createDate };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(ECOSYSTEM, ecosystemImage.ecosystem).map(CODE, ecosystemImage.code).map(DESCRIPTION, ecosystemImage.description).map(LOCATION, ecosystemImage.location).map(AUTHOR, ecosystemImage.author).map(URL, ecosystemImage.url).map(CREATE_DATE, ecosystemImage.createDate);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, ecosystemImage);
    }
}
